package 富婆梦.第一阶段.第七周IO流;

import java.io.*;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.第七周
 * @ClassName: TestDataOutputStream
 * @Author: hemengjin
 * @Description: 测试文件写入数据
 * @Date:2021/9/9 15:47
 * @Version: 1.0
 */
public class TestDataOutputStream {
    public static void main(String[] args) {
        File file = new File("D:/何梦锦的宝藏/Java学习/2.txt");
        try {
            //写入文件
            FileOutputStream fo = new FileOutputStream(file);
            BufferedOutputStream bo = new BufferedOutputStream(fo);
            DataOutputStream in =new DataOutputStream(bo);
            in.writeInt(1);
            in.writeUTF("true haha");
            in.writeDouble(3.154);
            in.writeChar('a');
            in.close();

            //读取文件
            FileInputStream fs = new FileInputStream(file);
            BufferedInputStream sb = new BufferedInputStream(fs);
            DataInputStream ds = new DataInputStream(sb);

            System.out.println(ds.readInt());
            System.out.println(ds.readUTF());
            System.out.println(ds.readDouble());
            System.out.println(ds.readChar());


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
